﻿using RpcHelper;
using RpcModularModel.Shield;
using RpcModularModel.Shield.Model;

namespace RpcModular.Domain
{
    internal class ResourceShield : DataSyncClass
    {

        private readonly string _Path;
        private volatile bool _IsShieId = true;

        public ResourceShield(string path)
        {
            this._Path = path;
        }

        public bool IsShieId => this._IsShieId;
        private long _BeOverTime = 0;
        protected override void SyncData()
        {
            this._Init();
        }
        private void _Init()
        {
            ShieldDatum shield = new CheckIsShieId
            {
                Path = _Path
            }.Send();
            this._IsShieId = shield.IsShieId;
            this._BeOverTime = shield.OverTime == 0 ? int.MaxValue : shield.OverTime;
        }
        public void CheckIsOverTime(long now)
        {
            if (this._IsShieId && this._BeOverTime <= now)
            {
                this._IsShieId = false;
            }
        }

        public override void ResetLock()
        {
            this._Init();
        }
    }
}
